﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using LeadVinaglue.Models.ViewPages;
using LeadVinaglue.Repository;

namespace LeadVinaglue.Areas.Management.Controllers
{
    public class DashboardController : Controller
    {
        // Create an instance of user manage
        LeadVinaglue.Repository.DashboardManagementRepository repository = new LeadVinaglue.Repository.DashboardManagementRepository();

        #region #Product Dashboard
        // GET: /Management/Dashboard/
        [Authorize(Roles = "SuperAdministrator")]
        public ActionResult Index()
        {
            DashboardManagementModel model = new DashboardManagementModel();
            model = repository.GetModel(Helpers.Constant.HOME, "SuperAdministrator", "PRODUCT");

            return View(model);
        }
        // GET: /Management/Dashboard/
        [Authorize(Roles = "SuperAdministrator")]
        public ActionResult ProductApproval()
        {
            DashboardManagementModel model = new DashboardManagementModel();
            model = repository.GetModelPA(Helpers.Constant.HOME, "SuperAdministrator", 50);

            return View(model);
        }

        [Authorize(Roles = "SuperAdministrator")]
        public ActionResult GetProduct(string startDate)
        {
            DashboardManagementModel model = new DashboardManagementModel();
            DateTime currentDate = DateTime.Parse(startDate);

            model = repository.GetModel(currentDate, "PRODUCT");

            return Json(model);
        }

        [Authorize(Roles = "SuperAdministrator")]
        public ActionResult ProductFolow()
        {
            DashboardManagementModel model = new DashboardManagementModel();
            model = repository.GetModel("PRODUCT");

            return Json(model);
        }

        // Ajax function post
        [HttpPost]
        public ActionResult SetProduct(int id)
        {
            DashboardManagementModel model = new DashboardManagementModel();
            model = repository.GetModelPAApproved(Helpers.Constant.HOME, "SuperAdministrator", 50, id);

            return Json(model);
        }

        // Ajax function post
        [HttpPost]
        public ActionResult ApproveItems(string id)
        {
            // approved items
            string[] arr = id.Split(',');
            if (arr.Length > 0)
            {
                ProductManagementRepository prod = new ProductManagementRepository();

                foreach (var item in arr)
                {
                    prod.Approved(int.Parse(item), 1);
                }
            }

            DashboardManagementModel model = new DashboardManagementModel();
            model = repository.GetModelPAApproved(Helpers.Constant.HOME, "SuperAdministrator", 50);

            return Json(model);
        }

        [HttpPost]
        public ActionResult DeleteProduct(int id)
        {
            DashboardManagementModel model = new DashboardManagementModel();
            model = repository.GetModelPADelete(Helpers.Constant.HOME, "SuperAdministrator", 50, id);

            return Json(model);
        }
        #endregion

        #region #Advertising Dashboard
        //
        // GET: /Management/Dashboard/
        [Authorize(Roles = "SuperAdministrator")]
        public ActionResult Advertise()
        {
            DashboardManagementModel model = new DashboardManagementModel();
            model = repository.GetModel(Helpers.Constant.HOME, "SuperAdministrator", "BANNER");

            return View(model);
        }

        [Authorize(Roles = "SuperAdministrator")]
        public ActionResult GetBanner(string startDate)
        {
            DashboardManagementModel model = new DashboardManagementModel();
            DateTime currentDate = DateTime.Parse(startDate);

            model = repository.GetModel(currentDate, "BANNER");

            return Json(model);
        }

        [Authorize(Roles = "SuperAdministrator")]
        public ActionResult BannerFolow()
        {
            DashboardManagementModel model = new DashboardManagementModel();
            model = repository.GetModel("BANNER");

            return Json(model);
        }
        #endregion
    }
}
